// 引入count的ui组件
import CountUI from "../../components/Count"
import {createAddAction,createReduceAction,createAsynReduceAction} from '../../redux/count_action'

// 引入connect用于连接ui组件与redux
import {connect} from 'react-redux'

/* 
    mapStateTopProps函数返回是一个对象
    返回对象中传入的参数为ui组建的props的key,value就是传递给ui组件的value
    mapStateTopProps用于传递状态
*/
function mapStateTopProps(state){
    return {count:state}
}

/* 
    mapDispatchTopProps函数返回是一个对象
    返回对象中传入的参数为ui组建的props的key,value就是传递给ui组件的value
    mapStateTopProps用于传递操作状态的方法
*/
function mapDispatchTopProps(dispatch){
    return {
        jia:number=>dispatch(createAddAction(number)),
        jian:number=>dispatch(createReduceAction(number)),
        yibujia:(number,time)=>dispatch(createAsynReduceAction(number,time))
    }
}


// 使用connect()()创建并暴露一个Count的容器组件
export default connect(mapStateTopProps,mapDispatchTopProps)(CountUI)